package com.project.repositoryImpl;

import com.Entity.DzmHisSchedulingEntity;
import com.project.repository.RepositoryDzmHisScheduling;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.persistence.MapKey;
import java.util.List;
import java.util.Map;

/**
 * ClassName: RepositoryDzmHisSchedulingImpl <br/>
 * Description: <br/>
 * date: 2018/12/27 15:11<br/>
 *
 * @author lenovo<br   />
 * @since JDK 1.8
 */

public interface RepositoryDzmHisSchedulingImpl extends JpaRepository<DzmHisSchedulingEntity, Integer>, RepositoryDzmHisScheduling {

    @Override
    /*@Cacheable(keyGenerator = "wiselyKeyGenerator",cacheNames = "weather")*/
    @Query(value = "select b.subsection_type,d.* ,c.scheduling_week_id " +
            "from dzm_his_scheduling a " +
            "inner join dzm_his_scheduling_subsection b on a.scheduling_id = b.scheduling_id " +
            "inner join  dzm_his_scheduling_week c on b.scheduling_subsection_id = c.scheduling_subsection_id " +
            "INNER JOIN dzm_his_doctor d on a.physicianid = d.id " +
            "where a.physicianid = :doctor_id and a.department_id = :did and a.company_id = :cid and DATE_FORMAT(c.date,'%Y-%m-%d') = DATE_FORMAT(now(),'%Y-%m-%d')", nativeQuery = true)
    List<Map<String, String>> getSchedulingInfo(@Param("doctor_id") String doctor_id, @Param("cid") String cid, @Param("did") String did);

    @Override/*
    @Cacheable(keyGenerator = "wiselyKeyGenerator",cacheNames = "weather")*/
    @Query(value = "select b.subsection_type,d.*,c.scheduling_week_id " +
            "from dzm_his_scheduling a " +
            "inner join dzm_his_scheduling_subsection b on a.scheduling_id = b.scheduling_id " +
            "inner join  dzm_his_scheduling_week c on b.scheduling_subsection_id = c.scheduling_subsection_id " +
            "INNER JOIN dzm_his_doctor d on a.physicianid = d.id " +
            "where a.physicianid = :doctor_id and a.department_id = :did and a.company_id = :cid and DATE_FORMAT(c.date,'%Y-%m-%d') = DATE_FORMAT(:date,'%Y-%m-%d')", nativeQuery = true)
    List<Map<String, Object>> getScheduling(@Param("doctor_id") String doctor_id, @Param("cid") String cid, @Param("did") String did, @Param("date") String date);


    @Override
    /*@Cacheable(keyGenerator = "wiselyKeyGenerator",cacheNames = "weather")*/
    @Query(value = "select b.subsection_type,d.* ,c.scheduling_week_id " +
            "from dzm_his_scheduling a " +
            "inner join dzm_his_scheduling_subsection b on a.scheduling_id = b.scheduling_id " +
            "inner join  dzm_his_scheduling_week c on b.scheduling_subsection_id = c.scheduling_subsection_id " +
            "INNER JOIN dzm_his_doctor d on a.physicianid = d.id " +
            "where  a.department_id = :did and a.company_id = :cid and DATE_FORMAT(c.date,'%Y-%m-%d') = DATE_FORMAT(:date1,'%Y-%m-%d')", nativeQuery = true)
    List<Map<String, Object>> getAllNowDector(@Param("cid") String cid, @Param("did") String did, @Param("date1") String date);

    @Override
    /*@Cacheable(keyGenerator = "wiselyKeyGenerator",cacheNames = "weather")*/
    @Query(value = "SELECT c.scheduling_week_id,e.registeredfee_aggregate_amount,d.id,b.scheduling_subsection_id,c.date,a.scheduling_id,a.department_id,f.department_name,a.physicianid,a.company_id,g.clinic_name,c.`week`,c.registeredfee_id,b.subsection_type,d.true_name,e.registeredfee_fee  " +
            "FROM dzm_his_scheduling a " +
            "INNER JOIN dzm_his_scheduling_subsection b ON a.scheduling_id = b.scheduling_id " +
            "INNER JOIN dzm_his_scheduling_week c ON b.scheduling_subsection_id = c.scheduling_subsection_id " +
            "INNER JOIN dzm_his_doctor d ON a.physicianid = d.id " +
            "INNER JOIN dzm_his_registeredfee e on e.reg_id = c.registeredfee_id  " +
            "INNER JOIN dzm_his_department f on f.did = a.department_id " +
            "INNER JOIN dzm_his_clinic g on g.cid = a.company_id " +
            "WHERE c.scheduling_week_id = :scheduling_week_id", nativeQuery = true)
    Map<String, Object> getChooseInfo(@Param("scheduling_week_id") String scheduling_week_id);
}
